package com.huayi.order.repository;

import com.huayi.order.entity.DcManageUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 描述：
 * 管理员Repository
 *
 * @author qlp
 * @date 2018-12-26 5:05 PM
 */
@Repository
public class DcManageUserRepository {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 根据用户名查询用户
     *
     * @param userName
     * @return
     */
    public DcManageUserEntity getUserByUserName(String userName) {
        String sql = "SELECT * FROM " + Tables.DcManageUser + " WHERE user_name=? or mobile= ? LIMIT 1";
        List<DcManageUserEntity> users = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DcManageUserEntity.class), userName, userName);
        if (users == null || users.size() == 0) return null;
        else return users.get(0);
    }




}
